package com.yuchen.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 *
 *
 */
public class SpringContextUtils {

    private static ApplicationContext ctx;

    private  static SpringContextUtils instance = null;

    private SpringContextUtils(ApplicationContext ctx) {
       this.ctx = ctx;
    }

    //初始化
    public static synchronized void me(ApplicationContext ctx) {
        if (null == instance) {
            instance = new SpringContextUtils(ctx);
        }
    }

    /**
     * 获得Spring管理的bean
     * @param
     * @return
     */
    public static <T> T getBean(Class<T> t){
        return ctx.getBean(t);
    }

}
